package com.luo.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    public static final String Key = "WALSHLSHAWLLJLSHLLJLSH52013142005072920060101";
    public static final long EXPIRE = 1000 * 60 * 60 * 24;

    public static String getToken(Map<String, Object> claims) {
        return Jwts.builder()
                .addClaims(claims)
                .signWith(SignatureAlgorithm.HS256, Key)
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRE))
                .compact();
    }


    public static Claims parseToken(String token) {
        return Jwts.parser()
                .setSigningKey(Key)
                .parseClaimsJws(token)
                .getBody();
    }


    public static Integer  getUserId(String token) {
        Claims claims = parseToken(token);
        return (Integer) claims.get("userId");
    }
}
